package cn.lzm.org.controller;

import cn.lzm.basic.util.AjaxResult;
import cn.lzm.basic.util.PageList;
import cn.lzm.org.domain.SystemDictionaryDetail;
import cn.lzm.org.query.SystemDictionaryDetailQuery;
import cn.lzm.org.service.ISystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sdd")
public class SystemDictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService systemDictionaryDetailService;
    @PostMapping("/addorup")
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        if (null == systemDictionaryDetail.getId() ) {
            systemDictionaryDetailService.add(systemDictionaryDetail);
        } else {
            systemDictionaryDetailService.update(systemDictionaryDetail);
        }
        return AjaxResult.me().success();
    }
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id ){
        systemDictionaryDetailService.remove(id);
        return AjaxResult.me().success();
    }
    @GetMapping
    public List<SystemDictionaryDetail> findAll(){
        return systemDictionaryDetailService.queryAll();
    }

    @GetMapping("/{id}")
    public SystemDictionaryDetail findById(@PathVariable("id") Long id){
        return systemDictionaryDetailService.queryById(id);
    }
    @PostMapping
    public PageList<SystemDictionaryDetail> queryByPage(@RequestBody SystemDictionaryDetailQuery query){
        return systemDictionaryDetailService.queryPage(query);
    }

    /**
     * 抽屉
     * 根据查询类型下的详细
     */
    @GetMapping("/typesId/{typesId}")
    public List<SystemDictionaryDetail> findByTypesIdSystemDictionaryDetails(@PathVariable("typesId") Long typesId){
        return  systemDictionaryDetailService.findByTypesIdSystemDictionaryDetails(typesId);
    }
}
